package com.sc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sc.mapper.UserMapper;
import com.sc.pojo.User;
import com.sc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.TreeSet;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper mapper;

    @Override
    public User login(User u) {
        return mapper.login(u);
    }

    @Override
    public User selectById(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int add(User u) {
        return mapper.insertSelective(u);
    }

    @Override
    public int del(Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int upd(User u) {
        return mapper.updateByPrimaryKeySelective(u);
    }

    @Override
    public PageInfo<User> show(Integer pageNum, Integer pageSize, Integer type, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<>(mapper.query(keyword,type));
    }

    @Override
    public List<User> queryByRoleid(Integer roleid) {
        return mapper.query(null,roleid);
    }

    @Override
    public User queryByCid(Integer cid) {
        return mapper.checkTeacher(cid);
    }

    @Override
    public boolean checkUser(String account) {
        if (mapper.checkUser(account) != null) return true;
        return false;
    }

    @Override
    public boolean checkTeacher(Integer classid) {
        if (mapper.checkTeacher(classid) != null) return true;
        return false;
    }

    @Override
    public List<String> delAll(Integer[] ids) {
        mapper.delAll(ids);
        return mapper.selectHeadpicById(ids);
    }

    @Override
    public int openAll(Integer[] ids) {
        return mapper.openAll(ids);
    }

    @Override
    public int closeAll(Integer[] ids) {
        return mapper.closeAll(ids);
    }

}
